﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Medlcalcare.MVC.Model
{
    /// <summary>
    /// 诊断请求模型
    /// 职责：数据验证与格式化
    /// </summary>
    public class DiagnosisRequest
    {
        [Required(ErrorMessage = "症状描述不能为空")]
        [StringLength(500, ErrorMessage = "描述不能超过500字")]
        [MedicalTermValidation]
        public string Symptoms { get; set; }

        [StringLength(200, ErrorMessage = "病史描述不能超过200字")]
        public string? PatientHistory { get; set; }
    }

    /// <summary>
    /// 自定义医学术语验证属性
    /// 确保输入包含有效医学描述
    /// </summary>
    public class MedicalTermValidationAttribute : ValidationAttribute
    {
        private static readonly string[] _validTerms = { "咳嗽", "发热", "头痛" }; // 示例白名单

        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            var input = value as string;
            if (string.IsNullOrEmpty(input)) return ValidationResult.Success;

            // 检查是否包含至少一个有效医学术语
            if (!_validTerms.Any(term => input.Contains(term)))
            {
                return new ValidationResult("请输入更具体的医学症状描述");
            }

            return ValidationResult.Success;
        }
    }

    public class DiagnosisResult
    {
        public string PossibleDiseases { get; set; }
        public string RecommendedTests { get; set; }
    }

}
